﻿//功能描述：首页-登录
using Dapper;
using Hong.Common.Encryption;
using Hong.Common.RabbitMQ;
using Hong.IRepository.IRepository_SystemSettings;
using Hong.Model;
using Hong.Model.Dto.PesponseDto.ResponseModel.ResultModel;
using Hong.Model.SysDomain.Model_SystemSettings.ViewModel;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hong.Repository.Repository.Repository_Home
{
    public class Login: ILogin
    {

        private static RabbitMqConfig _rabbitMqConfig;
        private readonly SecurityStatic _securityStatic;

        public Login(SecurityStatic  securityStatic, RabbitMqConfig rabbitMqConfig)
        {
            _rabbitMqConfig = rabbitMqConfig;
            _securityStatic = securityStatic;
        }



        #region 登录
        public ResponseModel<LoginModel> Lode(string PersonnelUserName, string PersonneIPassword)
        {
            
            using (IDbConnection conn = new SqlConnection(_securityStatic.Securityinfo()))
            {
                ResponseModel<LoginModel> res = new ResponseModel<LoginModel>();
                var list =conn.Query<LoginModel>($"select PersonnelId,PersonnelName,PersonnelUserName,HeadPortrait from Personnel where PersonnelUserName='{PersonnelUserName}' and PersonneIPassword='{PersonneIPassword}'").FirstOrDefault();
                if (list != null)
                {
                    return res.Succeed(list);
                }
                else
                {
                    _rabbitMqConfig.RabbitMqEmitLog("有不明身份登录,请注意");
                    return res.Fail("登陆失败");
                }
            }
        }
        #endregion

    }
}
